import { Component,Input, OnInit } from '@angular/core';
import { NziModalService } from 'ng-zorro-iop/modal/nzi-modal.service';
import { NzMessageService } from "ng-zorro-antd";
import { FcsService } from "../service/fcs.service";
import { LayerCreateComponent } from './create/layer-create.component';
import { Router } from "@angular/router";
import { CommonService } from './../service/common.service';
import { NavHeaderService } from '@global/layout/default/nav-header/nav-header.service';
import { Region } from './../shared-component/class/instance';


@Component({
  selector: 'app-layer',
  templateUrl: './layer.component.html',
  styleUrls: ['./layer.component.less']
})
export class LayerComponent implements OnInit {
  isLoading = true;
  pageNo = 1;
  pageSize = 10;
  totalCount = 0;
  layerList = [];
  searchValue = '';
  hasInputValue = false;
  errorMsg = '';
  currentRegion: Region = {
    regionCode: '',
    regionName: ''
  };
  

  constructor(
    private fcsService: FcsService,
    private modalService: NziModalService,
    private msgService: NzMessageService,
    private router: Router,
    private commonService: CommonService,
    private navHeaderService: NavHeaderService,
  ) { }

  ngOnInit() {
    this.getLayerList();
  }

 

  createLayer() {
    
  }


  getLayerList(){
    this.isLoading = true;
    this.hasInputValue = this.searchValue == '' ? false : true;
    this.fcsService.getLayerList(this.pageNo, this.pageSize,this.searchValue).subscribe(res => {
      this.totalCount = res.totalCount;
      // this.pageNo = res.pageNo;
      // this.pageSize = res.pageSize;
      this.layerList = res.result;
      this.isLoading = false;
      this.currentRegion.regionCode = this.layerList["regionCode"];
      this.currentRegion.regionName = this.layerList["regionName"];
      // console.log( res)
    }, error => {
      this.isLoading = false;
    })
  }

  

  updatelayer(layerId){
    this.router.navigate(['/layer/update'],{queryParams:{layerId:layerId,regionCode:this.currentRegion.regionCode,regionName:this.currentRegion.regionName}});
  }

  

  refresh(){
    this.getLayerList();
  }

}
